package com.qidian.buy.controller;

import com.qidian.buy.pojo.Item;
import com.qidian.buy.pojo.ItemDesc;
import com.qidian.buy.service.ItemService;
import com.qidian.buy.util.pojo.QdResult;
import com.qidian.buy.vo.ItemVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 戴着假发的程序员
 * @company 起点编程
 * @date 2023/9/11 9:44
 */
@RestController
@RequestMapping("/item")
public class ItemController {
    @Autowired
    private ItemService itemService;

    @GetMapping("/list")
    public QdResult queryByPage(Item item, @RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10")int limit){
        return itemService.queryByPage(item,page,limit);
    }

    @PostMapping("/save")
    public QdResult save(@RequestBody ItemVO itemVo){
        QdResult result = itemService.saveWrapper(itemVo,itemVo.getItemDescText(),itemVo.getSpeIds());
        // 发送消息........
        return result;
    };

    @GetMapping("/get/{itemId}")  // {itemId}是一个占位符
    public QdResult get(@PathVariable long itemId){ //@PathVariable 表示这个参数从路径中获取
        return itemService.queryById(itemId);
    };
}
